package cn.vinann.demo.controller;

import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.vinann.demo.domain.akweb.ItbUser;

@RestController
@RequestMapping("/cache")
public class CacheController {

	
	/**
     * Using SpEL for conditional caching - only cache method executions when
     * the name is equal to "Joshua"
     */
	@RequestMapping("/message")
    @Cacheable(value="messageCache", condition="'patterncat'.equals(#name)")
    public String getMessage(String name) {
        System.out.println("当参数name的值为patterncat时缓存");
        return "Hello " + name + "!";
    }

	@RequestMapping("/user")
    @Cacheable(value = "usercache",keyGenerator = "myKeyGenerator")
    public ItbUser getReport(Long id, String ambNo, String appType) {
        System.out.println("无缓存的时候调用这里---数据库查询");
        ItbUser itbUser = new ItbUser();
        itbUser.setAmbNo(ambNo);
        itbUser.setId(id);
        itbUser.setAppType(appType);
        return itbUser;
    } 
}
